﻿@{
    Layout = null;
    List<string> tasknamelist = ViewBag.namelist as List<string>;
    //int mulid = ViewBag.Milestone;
}
@model ProjectManagement.Models._ImportModel
@using (Html.BeginForm("ImportTaskTplMilestone", "Project", FormMethod.Post))
{
    <table class="noline">
        <tr>
    
            <td>
                <label for="searchRole">
                    <strong>角色：</strong></label>
                @Html.DropDownList("searchRole", new[] { new SelectListItem() { Text = "所有角色", Value = "" } }, new { style = "width:145px;" })
            </td>
            <td>
                <label for="searchName">
                    <strong>任务名称：</strong></label>
                @Html.TextBox("searchName")
            </td>
            <td>
                <label for="searchMilestone">
                    <strong>里程碑：</strong></label>
                @Html.DropDownList("searchMilestone", new[] { new SelectListItem() { Text = "所有里程碑", Value = "" } }, new { style = "width:145px;" })
            </td>
            <td>
                <input onclick=" GetITTPage() " type="button" value="查询" style="width: 50px" />
            </td>
            <td>
                <div style="text-align: right;">
                    @Html.RadioButton("selectAll", "groupselect")全选
                    @Html.RadioButton("unselectAll", "groupselect")全不选 @*<a href="javascript:;" onclick="$(':checkbox[name=Templates]').attr('checked',true)"
                        style="margin-right: 20px;">全选</a> <a href="javascript:;" onclick="$(':checkbox[name=Templates]').attr('checked',false)">
                            全不选</a>*@</div>
            </td>
        </tr>
    </table>
    @Html.HiddenFor(x => x.ProjectID)
    
    @Html.Hidden("hidDefault")
    @Html.Hidden("hidMilestone")
    @*@(Html.Telerik().Grid<ProjectManagement.Models._Milestone>()
        .Name("Milestone")
    .DataKeys(keys => { keys.Add(item => item.ID); })
        .DataBinding(dataBinding =>
        {
            dataBinding.Ajax()
            .Select("_SelectIndex", "Milestone")
            .Insert("_InsertAjaxEditing", "Milestone")
            .Update("_SaveAjaxEditing", "Milestone")
            .Delete("_DeleteAjaxEditing", "Milestone");
        })
            .Columns(columns =>
            {
                columns.Bound(item => item.MilestoneName).Width(240);

            }).Resizable(r => r.Columns(true))
            .DetailView(view => view.ClientTemplate(
                Html.Telerik().TabStrip()
                    .Name("TabStrip_<#= ID #>")
                    .SelectedIndex(0)
                    .Items(items =>
                    {
                        items.Add().Text("任务模板").HtmlAttributes(new { style = "width:110px;text-align: center" }).Content(
                            Html.Telerik().Grid<ProjectManagement.Models._TaskTemplate>()
                                .Name("TaskTemplate_<#= ID #>")
                                .DataKeys(keys => { keys.Add(item => item.ID); })
                                .ClientEvents(events => events.OnEdit("onEdit")
                                .OnDataBinding("Grid_onDataBinding"))

                                .DataBinding(dataBinding =>
                                {
                                    dataBinding.Ajax()
                                        .Select("_SelectIndexMilestoneProject", "TaskTemplate", new { conferenceid = "<#= ID #>" });

                                })
                                .Columns(columns =>
                                {
                                    columns.Bound(c => c.ID)
                                    .ClientTemplate("<input type='checkbox' name='Templates' value='<#= ID #>' />")
                                        .Title("选择").Width(30);
                                    columns.Bound(item => item.Name).Width(100);
                                    columns.Bound(o => o.DateCount).Width(70);
                                    columns.Bound(o => o.RolePM).Width(100);
                                    columns.Bound(c => c.ID)
                                    .ClientTemplate("<a class='t-button' onclick='showtasksimple(<#= ID #>)'>详细</a>")
                                        //.ClientTemplate("　 <a href='task/operation/<#= ID #>'>操作</a>")
                                        .Title("操作").Width(100);



                                })
                                .Editable(editing => editing.Mode(GridEditMode.PopUp))
                                .Pageable(paging => paging.Style(GridPagerStyles.Status).PageOnScroll(true))
                                .Scrollable()
                                .Sortable()
                                .ToHtmlString()

                            );
                    })
                                                                                                                                        .ToHtmlString()
                                                                                                                                ))
                                                                                                                        .Editable(editing => editing.Mode(GridEditMode.PopUp))
                                                                                                                        .Pageable(paging => paging.Style(GridPagerStyles.Status).PageOnScroll(true))
                                                                                                                        .Scrollable(c => c.Height("570px"))
                                                                                                                .Resizable(resizing => resizing.Columns(true))
                                                                                                                        .Sortable()
                                                                                                                    )*@
    
    
    
@(Html.Telerik().Grid(Model.TemplateList.Where(x => tasknamelist.Contains(x.Name) == false))
        .Name("Grid")
        .Columns(columns =>
        {
            columns.Template(@<text>
<input type="checkbox" name="Templates" value="@item.ID" />
</text>).Title("选择").Width(30);
            columns.Bound(o => o.Name).Width(370);
            columns.Bound(o => o.DateCount).Width(70);
            columns.Bound(o => o.RolePM).Width(100);
            columns.Template(@<text> <a href="javascript:;" class="t-button" onclick="showtasksimple(@item.ID)">
                详细</a>
</text>).Title("管理").Width(50);
        })
        .Scrollable()
)
    <div style="text-align: right;">
        <input type="submit" class="t-button" value="保存" />
    </div>
}
@(Html.Telerik().Window()
    .Name("tasksimple")
    .Content(@<text>
<div class="dialogue-tasksimple">
    <div class="tasksimple-wrapper">
    </div>
</div></text>)
    .Width(600)
    .Height(250).Title("任务详情")
    .Modal(true).Visible(false).Draggable(true)
)
<script>
    function showtasksimple(id) {
        $.ajax({
            url: "/TaskTemplate/GetSimpleTask/" + id,
            type: "post",
            success: function (data, status) {
                $('.tasksimple-wrapper').html(data);
                var window = $('#tasksimple').data('tWindow');
                window.center().open();
            }
        });
    }

    function GetITTPage() {
        var currentProjectId = $("#ProjectID").val();
        var searchRole = $("#searchRole").val();
        var searchName = $("#searchName").val();
        var searchMilestone = $("#searchMilestone").val();
        var hidDefault = $("#searchRole").val();
        var hidMilestone = $("#searchMilestone").val();
        $.post('/Project/GetImpTaskTplSearch', { projectId: currentProjectId, searchRole: searchRole, searchName: searchName, hidDefault: hidDefault, searchMilestone: searchMilestone, hidMilestone: hidMilestone }, function (result) {
            $('.impTaskTpl-wrapper').html(result);
        });
    }
    $("#selectAll").click(function () {
        $("#unselectAll").attr("checked", false);
        $(':checkbox[name=Templates]').attr('checked', true);
    });
    $("#unselectAll").click(function () {
        $("#selectAll").attr("checked", false);
        $(':checkbox[name=Templates]').attr('checked', false);
    });
    $(function () {
        var hidDefault = $("#hidDefault").val();
        var hidMilestone = $("#hidMilestone").val();
        getRole(hidDefault);
        getMilestone(hidMilestone);

    })
    function getRole(id) {
        var url = "/Project/GetRole/";
        var SS = $("#hidDefault").val();
        $("#searchRole").find("option").remove();
        $("<option></option>").val("").text("所有角色").appendTo($("#searchRole"));
        $.getJSON(url, { 'name': "" }, function (data) {

            $.each(data, function (i, item) {

                $("<option></option>").val(item["Value"]).text(item["Text"]).appendTo($("#searchRole"));
            });
            if (id == "") {

            }
            else {
                $("#searchRole option[value='" + id + "']").attr("selected", true);
            }
        });

    }

    function Grid_onDataBinding(e) {
  
        var projectid = $("#ProjectID").val();
    
    
        e.data = {
            projectid: projectid
        };
    }
    function getMilestone(id) {
        var url = "/TaskTemplate/GetMilestone/";
        var SS = $("#hidMilestone").val();
        $("#searchMilestone").find("option").remove();
        $("<option></option>").val("").text("所有里程碑").appendTo($("#searchMilestone"));
        $.getJSON(url, { 'name': "" }, function (data) {

            $.each(data, function (i, item) {

                $("<option></option>").val(item["Value"]).text(item["Text"]).appendTo($("#searchMilestone"));
            });
            if (id == "") {

            }
            else {
                $("#searchMilestone option[value='" + id + "']").attr("selected", true);
            }
        });

    }
</script>
<style type="text/css">
    .noline
    {
    }
    .noline, .noline tr, .noline td
    {
        border: 0;
        padding: 2px;
    }
</style>
